﻿<cfcomponent>
<cfscript>
DB = 'chinalaohu';
dbt = 'user_vcode';

function getRandom(){
var rStr = "";
for(i=0;i<4;i=i+1){
rStr = rStr & Chr(RandRange(Asc("0"),Asc("9")));
};
return rStr;
}
newvcode = getRandom();
</cfscript>

	<cffunction name="errorlog" access="remote" returntype="string">
		<!---验证刚才登录过--->
    <cfscript>
		//出错次数
		errorlogcount = 0;
		</cfscript>
    <cfif isdefined('sid') and len(sid) gt 0>
      <cfquery datasource="#DB#" name="errlogcount">
      select * from user_vcode
      where sid = #sid#
      </cfquery>
      <cfif errlogcount.recordcount gt 0>
        <cfscript>			
        errorlogcount = errlogcount.counts + 1;
        </cfscript>
        <cfif errlogcount.counts lte 3>
          <cfquery datasource="#DB#">
          update user_vcode set
          counts = counts + 1
          where sid = #sid#
          </cfquery>
        <cfelse>
          <cfquery datasource="#DB#">
          update user_vcode set
          counts = counts + 1,
          vcode = '#newvcode#'
          where sid = #sid#
          </cfquery>
        </cfif>
      <cfelse>
        <cfscript>
        errorlogcount = 1;
        </cfscript>
        <!---第一次出错--->
        <cfquery datasource="#DB#">
        insert into user_vcode(sid)
        value(#sid#)
        </cfquery>   
      </cfif>
    </cfif>
    <cfreturn errorlogcount>
	</cffunction>
  
	<cffunction name="modvcode" access="remote" returntype="any">
  	<cfquery datasource="#DB#">
    update user_vcode set
    vcode = '#newvcode#',
    counts=counts+1
    where sid=#sid#
    </cfquery>
    <cfreturn newvcode>
    
  </cffunction>
  
  
  <cffunction access="remote" name="sidvcode" returntype="string" returnFormat="plain">
  	<cfquery datasource="#DB#" name="sidvcode">
    select vcode from #dbt#
    where sid = #sid#
    </cfquery>
    <cfscript>
    if (sidvcode.recordcount eq 0){
			rs = 0;
		}
		else {
			rs = sidvcode.vcode;
		}
    return rs;
		</cfscript>
  </cffunction>
  
  <cffunction name="createvcode" access="remote" returntype="any">
  <cfinvoke method="sidvcode" returnvariable="vcode" sid="#sid#">
	<cfscript>

	
  //captchaimagepath = getdirectoryfrompath(getcurrenttemplatepath()) & 'newcaptcha' & gettickcount() & '.png';
	captchaimagepath = getdirectoryfrompath(getcurrenttemplatepath()) & 'newcaptcha' & vcode & '.png';
	
/*	if (not isdefined('vcode')){
		vcode = getRandom();
	}*/
	
  </cfscript>
 <cfimage action="captcha" width="88" height="40" text="#vcode#" destination="#captchaimagepath#" difficulty="medium" fontSize="20" overwrite="yes">

   <!---<cfcontent reset="yes" type="image/png" file="#captchaimagepath#" deletefile="yes">--->
<!---  <cfimage action="captcha" width="88" height="40" text="#vcode#" difficulty="medium" fontSize="20">--->
  
  </cffunction>
  
</cfcomponent>